/**
 * 
 */
package com.fg.dao;

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.fg.model.ImageVO;
import com.fg.model.MemberVO;
import com.fg.model.ProductVO;
import com.fg.model.ReplyVO;
import com.fg.model.TestModel;



/**
 * @Package	: com.tp.dao
 * @File 	: ProductDao.java
 *
 * @Author 	: JosephChoi
 * @Date	: 2011. 8. 13.
 * @Version : 
 * @Comment	: Member Table DAO
 *
 */
public class ProductDao extends SqlMapClientDaoSupport {
	
	/**
	 * @Comment	: 제품을 등록시킨다. 
	 * @param ProductVO(필수 - p_name, p_detail, regist_type, seller)
	 * (옵션 - p_point)
	 * @return product_seq
	 * @throws Exception
	 */
	public int insertProduct(Map parameters) throws Exception{
		return (Integer)getSqlMapClientTemplate().insert("productQueries.insertProduct", parameters);
	}
	
	/**
	 * @Comment	: 제품에 대한 진행중인 리스트를 받아온다. 
	 * @param (#start#, #count#)
	 * @return List<ProductVO>
	 * @throws Exception
	 */
	public List<ProductVO> readProductList(Map parameters) throws Exception{
		return (List)getSqlMapClientTemplate().queryForList("productQueries.readProductList", parameters);
	}
	
	/**
	 * @Comment	: 제품에 대한 진행중인 리스트를 받아온다. 
	 * @param product_seq
	 * @return ProductVO (product_seq, p_name, p_detail, p_init_date, p_point, p_status, regist_type, seller)
	 * @throws Exception
	 */
	public ProductVO readProductFromProductSeq(int product_seq) throws Exception{
		return (ProductVO)getSqlMapClientTemplate().queryForObject("productQueries.readProductFromProductSeq", product_seq);
	}
	
	
	/**
	 * @Comment	: 제품의 regist_type이 "선물"일 때 제품에 대한 댓글의 리스트를 받아온다.
	 * @param product_seq
	 * @return List<ReplyVO>
	 * @throws Exception
	 */
	public List<ReplyVO> readReplyListFromProductSeq(int product_seq) throws Exception{
		return (List)getSqlMapClientTemplate().queryForList("productQueries.readReplyListFromProductSeq", product_seq);
	}
	
	
	/**
	 * @Comment	: 제품에 대한 참고사진의 리스트를 받아온다.
	 * @param product_seq
	 * @return List<ImageVO>
	 * @throws Exception
	 */
	public List<ImageVO> readProductImageListFromProductSeq(int product_seq) throws Exception{
		return (List)getSqlMapClientTemplate().queryForList("productQueries.readProductImageListFromProductSeq", product_seq);
	}
	
	
	/**
	 * @Comment	: regist_type이 '선물'인 제품에 대한 댓글을 입력한다.
	 * @param parameters(comment, product_seq, member_seq)
	 * @return reply_seq
	 * @throws Exception
	 */
	public int insertReply(Map parameters) throws Exception{
		return (Integer)getSqlMapClientTemplate().insert("productQueries.insertReply", parameters);
	}
	
	/**
	 * @Comment	: product의 상태를 업데이트한다.(주로 선물을 받을 때)
	 * @param parameters(product_status(1 or 2), buyer(member_seq), product_seq)
	 * @return count
	 * @throws Exception
	 */
	public int updateProduct(Map parameters) throws Exception{
		return (Integer)getSqlMapClientTemplate().update("productQueries.updateProduct", parameters);
	}
	
	/**
	 * @Comment	: 제품등록자가 맘에드는 댓글을 선택해서 선물을 주기 위해 reply를 선택
	 * @param reply_seq
	 * @return count
	 * @throws Exception
	 */
	public int checkReplyFromReplySeq(int reply_seq) throws Exception{
		return (Integer)getSqlMapClientTemplate().update("productQueries.checkReplyFromReplySeq", reply_seq);
	}
	
	/**
	 * @Comment	: 제품에 대한 이미지를 DB에 등록
	 * @param ImageVO
	 * @return product_image_seq
	 * @throws Exception
	 */
	public int insertProductImage(ImageVO image) throws Exception{
		return (Integer)getSqlMapClientTemplate().update("productQueries.insertProductImage", image);
	}
	
	public MemberVO readMemberFromMemberSeq(int member_seq) throws Exception{
		return (MemberVO)getSqlMapClientTemplate().queryForObject("productQueries.readMemberFromMemberSeq", member_seq);
	}
	
	
}
